import axios from 'axios'
import { ElMessage } from 'element-plus'

const request = axios.create({
    baseURL: import.meta.env.VITE_BASE_APP_URL,
    timeout: 10000
})

// 请求拦截
request.interceptors.request.use(config => {
    return config
}, err => {
    console.log(err);
})

// 响应拦截
request.interceptors.response.use(response => {
    let data = response.data;
    if (data.code == 200) {
        return data.data;
    } else {
        ElMessage(data.msg);
    }
}, err => {
    ElMessage('请求异常');
    console.log(err);
})

export default request;